let user = require('../../../utils/user')
let util = require('../../../utils/until')
let api = require('../../../config/api')

let app = getApp()


Page({
    data:{
        userInfo:{
            nickName:'点击登录',
            avatarUrl:'https://ci.xiaohongshu.com/1000g0081r5u7bs6f40cg5n48vlm41vb1lmekrsg?imageView2/2/w/1080/format/jpg'
        },
        hasLogin:false
    },
    //获取用户的登录信息
    onShow:function(){
      user.checkLogin().then(res=>{
        app.globalData.hasLogin = true;
        let userInfo = wx.getStorageSync('userInfo');
        this.setData({
          userInfo:userInfo,
          hasLogin:true
        })
      }).catch(()=>{
        app.globalData.hasLogin = false
      })
    },
    //去登陆页
    goLogin(){
        wx.navigateTo({
          url: '/pages/auth/login/login',
        })
    },
    //退出登录
    outLogin:function(){
      wx.showModal({
        title: '',
        content: '退出登录？',
        confirmColor:'#b4282d',
        success: (res) => {
          if (!res.confirm) {
            return
          }
          util.request(api.AuthLogout,{},'POST');
          app.globalData.hasLogin = false;
          wx.removeStorageSync('token');
          wx.removeStorageSync('userInfo');
          wx.reLaunch({
            url: '/pages/index/index',
          })
        }
      })
    }
})